<?php
/*
+--------------------------------------------------------------------------
|   WeCenter [#RELEASE_VERSION#]
|   ========================================
|   by WeCenter Software
|   © 2011 - 2014 WeCenter. All Rights Reserved
|   http://www.wecenter.com
|   ========================================
|   Support: WeCenter@qq.com
|
+---------------------------------------------------------------------------
*/

define('IN_AJAX', TRUE);


if (!defined('IN_ANWSION'))
{
	die;
}

class ajax extends AWS_CONTROLLER
{
	public function get_access_rule()
	{
		$rule_action['rule_type'] = 'white'; //黑名单,黑名单中的检查  'white'白名单,白名单以外的检查

		$rule_action['actions'] = array(
			'add_dept',
            'delete_dept'

		);

		return $rule_action;
	}



	public function setup()
	{
		HTTP::no_cache_header();
	}


	public function  add_dept_action(){


	    if(!$this->user_id){
            H::ajax_json_output(AWS_APP::RSM(null, -1, AWS_APP::lang()->_t('非法操作')));
        }
	    $name = $_POST['name'];
        $org = $this->model('org')->get_org_by_uid($this->user_id);

        $id = $_POST['id'];

        $data = array();
        $data['name'] = $name;
        $data['org_id']= $org['id'];

        if($id){
            $this->model('dept')->update_dept($data,$id);
        }else{
           $this->model('dept')->add_dept($data);

        }
        H::ajax_json_output(AWS_APP::RSM(null, 1, AWS_APP::lang()->_t('成功')));


    }

    public function delete_dept_action(){
        if(!$this->user_id){
            H::ajax_json_output(AWS_APP::RSM(null, -1, AWS_APP::lang()->_t('非法操作')));
        }
        $id = $_POST['id'];
        $this->model('dept')->delete_dept_by_id($id);
        H::ajax_json_output(AWS_APP::RSM(null, 1, AWS_APP::lang()->_t('成功')));

    }
}
